const BASE_URL = "http://192.168.124.25:8080/coach"

export const request = (options) => {
  return new Promise((resolve, reject) => {
    uni.request({
      url: BASE_URL + options.url,
      method: options.method || 'GET',
      data: options.data,
      header: {
        'Content-Type': 'application/json',
        // 可加 token
        // 'Authorization': uni.getStorageSync('token')
		'coachId': uni.getStorageSync('coachId')
	  },
      success: (res) => {
        const { code } = res.data || 200
        if (code === 200 || code === 0) {
          resolve(res.data)
        } else if (code === 401) {
			console.log(res)
          uni.showToast({ title: '请登录', icon: 'none' })
          // 跳转登录页
        } else {
          uni.showToast({ title: res.data.msg || '请求失败', icon: 'none' })
          reject(new Error(res.data.msg))
        }
      },
      fail: (err) => {
        uni.showToast({ title: '网络异常', icon: 'none' })
        reject(err)
      }
    })
  })
}